export enum LogType {
  Success = 'success',
  Error = 'error',
  Warning = 'warning',
  Info = 'info',
}

class Logger {
  public static loggerMap: Map<string, Logger> = new Map();

  private _log = console.log;

  private readonly _commonStyleText = `color: #fff; font-weight: bold; padding: 5px; box-sizing: border-box; border-radius: 3px;`;
  
  constructor(
    private readonly field: string,
  ) {
    if (Logger.loggerMap.has(this.field)) {
      throw new Error(`Logger for ${this.field} already exists`);
    }
    Logger.loggerMap.set(this.field, this);
  }

  public success(message: string,) {
    // 添加样式，并打印
    this._log(`%c【${this.field}】${message}`, `background-color: #d1edc4; ${this._commonStyleText}`);
  }

  public error(message: string) {
    // 添加样式，并打印
    this._log(`%c【${this.field}】${message}`, `background-color: #fcd3d3; ${this._commonStyleText}`);
  }

  public warning(message: string) {
    // 添加样式，并打印
    this._log(`%c【${this.field}】 ${message}`, `background-color: #f8e3c5; ${this._commonStyleText}`);
  }

  public info(message: string) {
    // 添加样式，并打印
    this._log(`%c【${this.field}】${message}`, `background-color: #79bbff; ${this._commonStyleText}`);
  }
}

function createLogger(filed: string) {
  return new Logger(filed);
}

export const globalLogger = createLogger('global');

export const homeLogger = createLogger('home');

export const detailLogger = createLogger('detail');

export const listLogger = createLogger('list');

export const searchLogger = createLogger('search');
